#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
ll T,n,m,L,V,d[100005],v[100005],a[100005],p[100005],ans1,ans2;
ll s[1000005];
bool qry(int l,int r){
    return s[r]-s[l-1]>0;
}
ll sq(ll x){
    return x*x;
}
vector<pii>c,t;
void solve(){
    scanf("%lld%lld%lld%lld",&n,&m,&L,&V),ans1=ans2=0;
    t.clear(),c.clear();
    for(int i=0;i<=L;i++)s[i]=0;
    for(int i=1;i<=n;i++)scanf("%lld%lld%lld",d+i,v+i,a+i);
    for(int i=1;i<=m;i++)scanf("%lld",p+i),s[p[i]]++;
    for(int i=1;i<=L;i++)s[i]+=s[i-1];
    for(int i=1;i<=n;i++){
        ll l=0,r=0;
        if(a[i]==0){
            if(v[i]<=V)continue;
            else l=d[i],r=L;
        }
        else if(a[i]>0){
            if(v[i]>V)l=d[i],r=L;
            else{
                r=L;
                if((sq(V)-sq(v[i]))%(2*a[i])==0)
                    l=(sq(V)-sq(v[i]))/(2*a[i])+d[i]+1;
                else
                    l=d[i]+floor((sq(V)-sq(v[i]))/(2.0*a[i]))+1;
            }
        }
        else{
            if(v[i]<=V)continue;
            l=d[i];
            //if(i==1)cout<<sq(V-v[i])/(-2*a[i])<<endl;
            if((sq(v[i])-sq(V))%(-2*a[i])==0)
                r=(sq(v[i])-sq(V))/(-2*a[i])+d[i]-1;
            else
                r=d[i]+floor((sq(v[i])-sq(V))/(-2.0*a[i]));
            r=min(r,L);
        }
        if(l>L)continue;
        //cout<<i<<" "<<l<<" "<<r<<endl;
        if(qry(l,r))
            ans1++,t.push_back({l,r});
    }
    sort(t.begin(),t.end());
    for(auto &&i:t){
        while(c.size()&&i.se<=c.back().se)c.pop_back();
        c.push_back(i);
    }
    if(ans1){
        int j=1;ans2=1;
        while(j<m&&p[j+1]<=c[0].se)j++;
        for(auto &&i:c){
            if(i.fi<=p[j])continue;
            ans2++;
            while(j<m&&p[j+1]<=i.se)j++;
        }
    }
    printf("%lld %lld\n",ans1,m-ans2);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%lld",&T);
    while(T--)solve();
    return 0;
}
